<template>
    <div class="resumedetailmsg">
        <van-nav-bar title="详细信息" left-text="" @click-right="savexxmsg" fixed placeholder left-arrow @click-left="$router.back()">
            <template #right>
                <span>保存</span>
            </template>
        </van-nav-bar>
         <div class="content">
                <van-cell-group style="height:70px">
                    <div class="contents-item" >
                        <span>身份证号</span>
                        <van-field v-model="jbform.idnumber" clickable placeholder="请输入身份证号">
                        </van-field>
                    </div>
                </van-cell-group>
                <van-cell-group style="height:70px">
                    <div class="contents-item" >
                        <span>籍贯</span>
                        <van-field v-model="jbform.jiguan" clickable placeholder="请输入籍贯">
                        </van-field>
                    </div>
                </van-cell-group>
                <van-cell-group style="height:70px">
                    <div class="contents-item" >
                        <span>民族</span>
                        <van-field v-model="jbform.minzu" clickable placeholder="请输入民族">
                        </van-field>
                    </div>
                </van-cell-group>
                <van-cell-group style="height:70px">
                    <div class="contents-item">
                        <span>婚姻状况</span>
                        <van-field v-model="jbform.hunyinzk" readonly clickable is-link  placeholder="请选择婚姻状况" @click="show1 = true">
                        </van-field>
                        <van-popup v-model="show1" position="bottom">
                            <van-picker title="选择婚姻状况" show-toolbar :columns="columns" @cancel="show1 = false" @confirm="onConfirm" />
                        </van-popup>
                    </div>
                </van-cell-group>
                 <van-cell-group style="height:70px">
                    <div class="contents-item">
                        <span>QQ号码</span>
                        <van-field v-model="jbform.qqnumber" clickable  placeholder="请输入QQ号码">
                        </van-field>
                    </div>
                </van-cell-group>
                <van-cell-group style="height:70px">
                    <div class="contents-item">
                        <span>微信号码</span>
                        <van-field v-model="jbform.wxnumber" clickable  placeholder="请输入微信号码">
                        </van-field>
                    </div>
                </van-cell-group>

                <van-cell-group style="height:70px">
                    <div class="contents-item">
                        <span>户口所在地详细地址</span>
                        <van-field v-model="jbform.hukouaddress" clickable  placeholder="请输入户口所在地详细地址">
                        </van-field>
                    </div>
                </van-cell-group>
                <van-cell-group style="height:70px">
                    <div class="contents-item">
                        <span>现居住地详细地址</span>
                        <van-field v-model="jbform.xianjuaddress" clickable  placeholder="请输入现居住地详细地址">
                        </van-field>
                    </div>
                </van-cell-group>
                <van-cell-group style="height:70px">
                    <div class="contents-item">
                        <span>毕业院校</span>
                        <van-field v-model="jbform.biyeschool" clickable  placeholder="请输入毕业院校">
                        </van-field>
                    </div>
                </van-cell-group>
                 <van-cell-group style="height:70px">
                   <div class="contents-item">
                        <span>毕业时间</span>
                        <van-field v-model="jbform.biyetime" is-link readonly @click="show2 = true" placeholder="选择毕业时间">
                        </van-field>
                        <van-popup v-model="show2" position="bottom">
                            <van-datetime-picker type="date" title="选择年月日" @confirm="setbiyeTime($event)" :min-date="minDate" :max-date="maxDate" @cancel="show2 = false" />
                        </van-popup>
                   </div>
                </van-cell-group>
                <van-cell-group style="height:70px">
                    <div class="contents-item">
                        <span>学历</span>
                        <van-field v-model="jbform.xueli" clickable  placeholder="请输入学历">
                        </van-field>
                    </div>
                </van-cell-group>
                <van-cell-group style="height:70px">
                    <div class="contents-item">
                        <span>证书</span>
                        <van-field v-model="jbform.zhengshu" clickable  placeholder="请输入证书">
                        </van-field>
                    </div>
                </van-cell-group>
                <van-cell-group style="height:70px">
                    <div class="contents-item">
                        <span>身高</span>
                        <van-field v-model="jbform.height" clickable  placeholder="请输入身高">
                        </van-field>
                    </div>
                </van-cell-group>
                <van-cell-group style="height:70px">
                    <div class="contents-item">
                        <span>体重</span>
                        <van-field v-model="jbform.weight" clickable  placeholder="请输入体重">
                        </van-field>
                    </div>
                </van-cell-group>
                <van-cell-group style="height:70px">
                    <div class="contents-item">
                        <span>政治面貌</span>
                        <van-field v-model="jbform.politics" clickable  placeholder="请输入政治面貌">
                        </van-field>
                    </div>
                </van-cell-group>
                <van-cell-group style="height:70px">
                    <div class="contents-item">
                        <span>计算机水平</span>
                          <van-field v-model="jbform.computersp" readonly clickable is-link placeholder="点击选择" @click="show3 = true">
                          </van-field>
                          <van-popup v-model="show3" position="bottom">
                            <van-picker title="选择计算机水平" show-toolbar :columns="columnsjsjsp" @cancel="show3 = false" @confirm="onConfirmCumputerSp" />
                          </van-popup>
                    </div>
                </van-cell-group>
                <van-cell-group style="height:70px">
                    <div class="contents-item">
                        <span>外语水平</span>
                        <van-field v-model="jbform.waiyusp" readonly clickable is-link placeholder="点击选择" @click="show4 = true">
                        </van-field>
                        <van-popup v-model="show4" position="bottom">
                          <van-picker title="选择外语水平" show-toolbar :columns="columnsSp" @cancel="show4 = false" @confirm="onConfirmwaiyuSp" />
                        </van-popup>
                    </div>
                </van-cell-group>
            </div>
    </div>
</template>
<script>
export default {
    data(){
        return{
            show1:false,
            show2:false,
            show3:false,
            show4:false,
            minDate: new Date(1980, 0, 1),
            maxDate: new Date(2025, 10, 1),
            columns:["已婚","未婚","离异"],
            columnsjsjsp: ["优秀", "良好", "一般"],
            columnsSp: ["优秀", "良好", "一般"],
            jbform:{
                idnumber:"",
                jiguan:"",
                minzu:"",
                gztime:"",
                cstime:"",
                email:"",
                hunyinzk:"",
                qqnumber:"",
                wxnumber:"",
                biyeschool:"",
                biyetime:"",
                xueli:"",
                politics:"",
                height:"",
                weight:"",
                hukouaddress:"",
                xianjuaddress:"",
                computersp:"",
                waiyusp:"",
                zhengshu:""
            }
        }
    },
    mounted(){
        if(this.$route.query.id){
            this.getCustomerInfo(this.$route.query.id);
        }
    },
    methods:{
        getCustomerInfo (id) {
        this.$api.getCustomerInfo({id:id}).then(res=>{
          this.jbform.idnumber=res.data.idCard
          this.jbform.sex=res.data.gender
          this.jbform.jiguan=res.data.nativePlace
          this.jbform.minzu=res.data.nation
          this.jbform.hunyinzk=res.data.marriage
          this.jbform.height=res.data.height
          this.jbform.weight=res.data.weight
          this.jbform.politics=res.data.politicalStatus
          this.jbform.qqnumber=res.data.qqNumber
          this.jbform.wxnumber=res.data.weChatNo
          this.jbform.phone=res.data.phone
          this.jbform.speciality=res.data.speciality
          this.jbform.xianjuaddress=res.data.accountAddress
          this.jbform.hukouaddress=res.data.detailedAddress
          this.jbform.biyeschool=res.data.graduate
          this.jbform.biyetime=res.data.graduateTime
          this.jbform.xueli=res.data.education
          this.jbform.zhengshu=res.data.certificate
          this.jbform.computersp=res.data.computers
          this.jbform.waiyusp=res.data.foreignLanguages
         
        })
    },
        // 身份证校验
        testid(id) {
        // 1 "验证通过!", 0 //校验不通过 // id为身份证号码
            var format = /^(([1][1-5])|([2][1-3])|([3][1-7])|([4][1-6])|([5][0-4])|([6][1-5])|([7][1])|([8][1-2]))\d{4}(([1][9]\d{2})|([2]\d{3}))(([0][1-9])|([1][0-2]))(([0][1-9])|([1-2][0-9])|([3][0-1]))\d{3}[0-9xX]$/;
            //号码规则校验
            if(!format.test(id)){
            return {'status':0,'msg':'身份证号码不合规'};
            }
            //区位码校验
            //出生年月日校验  前正则限制起始年份为1900;
            var year = id.substr(6,4),//身份证年
            month = id.substr(10,2),//身份证月
            date = id.substr(12,2),//身份证日
            time = Date.parse(month+'-'+date+'-'+year),//身份证日期时间戳date
            now_time = Date.parse(new Date()),//当前时间戳
            dates = (new Date(year,month,0)).getDate();//身份证当月天数
            if(time>now_time||date>dates){
            return {'status':0,'msg':'出生日期不合规'}
            }
            //校验码判断
            var c = new Array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2);  //系数
            var b = new Array('1','0','X','9','8','7','6','5','4','3','2'); //校验码对照表
            var id_array = id.split("");
            var sum = 0;
            for(var k=0;k<17;k++){
            sum+=parseInt(id_array[k])*parseInt(c[k]);
            }
            if(id_array[17].toUpperCase() != b[sum%11].toUpperCase()){
            return {'status':0,'msg':'身份证校验码不合规'}
            }
            return {'status':1,'msg':'校验通过'}
        },
        // 详细信息保存
        savexxmsg(){
            if(this.jbform.idnumber==""){
                this.$toast("请输入身份证号");
                return;
            }else if(this.jbform.idnumber.length>18){
                this.$toast("身份证号长度大于了18位");
                return;
            }else if(this.testid(this.jbform.idnumber).status==0){
                this.$toast(this.testid(this.jbform.idnumber).msg);
                return;
            }else if(this.jbform.jiguan==""){
                this.$toast("请输入籍贯");
                return;
            }else if(this.jbform.minzu==""){
                this.$toast("请输入民族");
                return;
            }else if(this.jbform.hunyinzk==""){
                this.$toast("请输入婚姻状况");
                return;
            }else if(this.jbform.qqnumber==""){
                this.$toast("请输入qq号码");
                return;
            }else if(this.jbform.wxnumber==""){
                this.$toast("请输入微信号码");
                return;
            }else if(this.jbform.hukouaddress==""){
                this.$toast("请输入户口详细地址");
                return;
            }else if(this.jbform.xianjuaddress==""){
                this.$toast("请输入现居详细地址");
                return;
            }else if(this.jbform.biyeschool==""){
                this.$toast("请输入毕业院校");
                return;
            }else if(this.jbform.biyetime==""){
                this.$toast("请选择毕业时间");
                return;
            }else if(this.jbform.xueli==""){
                this.$toast("请输入学历");
                return;
            }
            let obj={
                "id":this.$route.query.id,
                "idCard":this.jbform.idnumber,
                "nativePlace":this.jbform.jiguan,
                "nation":this.jbform.minzu,
                "marriage":this.jbform.hunyinzk,
                "qqNumber":this.jbform.qqnumber,
                "weChatNo":this.jbform.wxnumber,
                "accountAddress":this.jbform.hukouaddress,
                "detailedAddress":this.jbform.xianjuaddress,
                "graduate":this.jbform.biyeschool,
                "graduateTime":this.jbform.biyetime,
                "education":this.jbform.xueli,
                "certificate":this.jbform.zhengshu,
                "computers":this.jbform.computersp,
                "foreignLanguages":this.jbform.waiyusp,
                "height":this.jbform.height,
                "weight":this.jbform.weight,
                "politicalStatus":this.jbform.politics
            }
              this.$api.addRecruitTalent(obj).then(res=>{
                    if(res.code==0){
                        this.$toast("添加成功")
                        this.$router.push(`/detailedonlineresume?id=${this.$route.query.id}&recruitId=${this.$route.query.recruitId}`)
                    }else{
                        this.$toast("添加失败")
                    }
                })
        },
        // 处理时间的方法
        disposeDate (now) {
            var year = now.getFullYear(); //年
            var month = now.getMonth() + 1; //月
            var day = now.getDate(); //日
            if (String(month).length != 2) {
                month = 0 + String(month);
            }
            if (String(day).length != 2) {
                day = 0 + String(day);
            }
            return `${year}-${month}-${day}`;
        },
        //性别
        onConfirm (value) {
            this.jbform.hunyinzk = value
            this.show1 = false
        },
        // 出生年月
        setbiyeTime (time) {
            this.jbform.biyetime = this.disposeDate(new Date(time))
            this.show2= false;
        },
         // 计算机水平
        onConfirmCumputerSp (val) {
            this.jbform.computersp = val;
            this.show3 = false;
        },
        // 外语水平
        onConfirmwaiyuSp (val) {
            this.jbform.waiyusp = val;
            this.show4 = false
        },
    }
}
</script>
<style lang="less" scoped>

.content{
    margin: 0 auto;
    .content-item{
        margin: 0 auto;
        display: flex;
        justify-content: space-between;
        padding: 10px;
        span{
            display: block;
            margin-top: 0.7rem;
            padding-left: 15px;
        }
        img{
            width: 45px;
            height: 45px;
            border-radius: 2em;
        }
    }
    .contents-item{
        padding: 10px;
        line-height: 20px;
        span{
            padding-left: 15px;
        }
    }
}


</style>